import api from "../../../../../../common/api.js";
const app = getApp();

Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的配置
   */
  options: {
    styleIsolation: 'isolated',
    pureDataPattern: /^_/
  },

  /**
   * 组件的初始数据
   */
  data: {
    housePosterList: [],
  },

  /**
   * 组件的生命周期
   */
  lifetimes: {
    attached: function () {
      let t = this
      t.loadHousePosterList()
    },
    detached: function () {

    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 获取房源海报模板列表 
    loadHousePosterList() {
      let t = this
      api.getModelImg({
        modelType: "POSTERTEMPLATE"
      }, (res) => {
        let list = res.data.content || [];
        let housePosterList = list.map((item) => {
          return {
            img: item.imgUrl || '',
            tmpID: item.modelCode || '',
            tmpUniqueID: item.code || '',
            bgImg: item.backgroundImgUrl || ''
          }
        })
        t.setData({
          housePosterList,
        });
      });
    },

    onClickCard(e) {
      let t = this;
      let id = e.currentTarget.dataset.id || ''
      t.jumpToSelectHouse(id)
    },

    jumpToSelectHouse(id) {
      let t = this;
      let tmp = t.data.housePosterList.filter((item) => {
        return item.tmpUniqueID === id
      })
      app.globalData.posterTmp = tmp[0] || {}
      wx.navigateTo({
        url: `/pages/home/pickHouseList/pickHouseList?option=placard`
      })
    }
  }
})